﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Services;
using Common;
using EntityModel;
using System.Data.Entity;
using MvcPaging;

namespace Heart.Controllers
{
    public class AdvertisingController : Controller
    {
        #region 公用属性
        private AdvertisingService advertisingService = new AdvertisingService();
        private int pageSize = ConfigHelper.PageSize();
        #endregion

        public ActionResult Index(int? page)
        {
            int PageIndex = page.HasValue ? (page.Value == 0 ? 0 : (page.Value - 1)) : 0;
            var list = advertisingService.GetAllList().ToPagedList(PageIndex, pageSize);
            return View(list);
        }
        public ActionResult Create()
        {
            return View();
        }
         [ValidateInput(false)]
        [HttpPost]
        public ActionResult Create(FormCollection f)
        {
            Advertising model = new Advertising();
            model.Name = WebBase.GetForm("Name");
            model.Names = WebBase.GetForm("Names");
            model.Contents = WebBase.GetForm("Contents");
            advertisingService.Create(model);
            return RedirectToAction("Index");
        }
         [ValidateInput(false)]
        public ActionResult Detail(int id)
        {
            var model = advertisingService.GetModel(id);
            return View(model);
        }
         [ValidateInput(false)]
        [HttpPost]
        public ActionResult Detail(Advertising model)
        {
            //Advertising a = new Advertising();
            //a.Contents = model.Contents);
            //a.Id = model.Id;
            //a.Name = model.Name;
            //a.Names = model.Names;
            advertisingService.Update(model);
          
            return RedirectToAction("Index");
            
        }

    }
}
